<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <title>自动补全：@、话题等关键字扩展/自定义表情/表情图片地址/表情提示 - Vditor</title>
    <meta name="robots" content="index,follow,archive">
    <meta name="description"
          content="Vditor - 易于使用的 Markdown 编辑器，为适配不同的应用场景而生。它使用 TypeScript 实现，支持原生 JavaScript、Vue、React、Angular，提供桌面版。"/>
    <meta name="copyright" content="B3log"/>
    <link rel="canonical" href="https://b3log.org/vditor/demo/advanced-hint.html">
    <link rel="apple-touch-icon" href="https://b3log.org/images/brand/vditor-128.png">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta http-equiv="Window-target" content="_top"/>
    <link rel="icon" type="image/png" href="https://b3log.org/images/brand/vditor-128.png"/>
    <link rel="shortcut icon" type="image/x-icon" href="https://b3log.org/images/brand/vditor-512.png"/>
    <link type="text/css" rel="stylesheet" href="https://b3log.org/css/base.css"/>

    <meta property="og:locale" content="zh_CN"/>
    <meta property="og:title" content="自动补全：@、话题等关键字扩展/自定义表情/表情图片地址/表情提示 - Vditor"/>
    <meta property="og:description"
          content="Vditor - 易于使用的 Markdown 编辑器，为适配不同的应用场景而生。它使用 TypeScript 实现，支持原生 JavaScript、Vue、React、Angular，提供桌面版。"/>
    <meta property="og:image" content="https://b3log.org/images/brand/vditor-128.png"/>
    <meta property="og:url" content="https://b3log.org/vditor"/>
    <meta property="og:site_name" content="B3log"/>
    <meta name="twitter:card" content="summary_large_image"/>
    <meta name="twitter:description"
          content="Vditor - 易于使用的 Markdown 编辑器，为适配不同的应用场景而生。它使用 TypeScript 实现，支持原生 JavaScript、Vue、React、Angular，提供桌面版。"/>
    <meta name="twitter:title" content="自动补全：@、话题等关键字扩展/自定义表情/表情图片地址/表情提示 - Vditor"/>
    <meta name="twitter:image" content="https://b3log.org/images/brand/vditor-128.png"/>
    <meta name="twitter:url" content="https://b3log.org/vditor"/>
    <meta name="twitter:site" content="@b3logos"/>
    <meta name="twitter:creator" content="@b3logos"/>
    <script src="https://b3log.org/vditor/vditor.js" defer></script>
    <style>
        .header {
            background-color: #fff;
            box-shadow: rgba(0, 0, 0, 0.05) 0 1px 7px;
            border-bottom: 1px solid #e1e4e8;
        }
    </style>
</head>
<body>
<div class="header fn-clear">
    <a class="header-logo" href="https://b3log.org/vditor">
        <img src="https://b3log.org/images/brand/vditor-128.png">
        <h1>Vditor</h1>
    </a>
    <div class="fn-clear">
        <a class="header-a" href="https://ld246.com/tag/vditor" target="_blank">社区</a>
        <a class="header-a header-red" target="_blank" href="https://ld246.com/article/1549638745630">API</a>
        <a class="header-a header-green current" href="index.html">Demo</a>
        <a class="header-a header-yellow" href="https://ld246.com/sponsor" target="_blank">成为赞助者</a>
    </div>
</div>
<div class="wrapper">
    <div class="fn-50"></div>
    相关 <a href="https://ld246.com/article/1549638745630#options-hint" target="_blank">API</a>：
    options.hint.emoji，options.hint.emojiTail，options.hint.emojiPath，options.hint.delay，options.hint.extend<br>
    ⚠️ 注意事项：
    <ul style="margin-left: 30px">
        <li>设置自定义表情后需输入 : 或点击工具栏上的表情按钮才可查看到效果</li>
        <li>设置表情提示文案后需点击工具栏上的表情按钮才可查看到效果</li>
        <li>设置表情图片地址后需在调试栏中查看表情图片地址才可看到效果，试一试 :wulina: 表情图片吧</li>
        <li>At、话题等扩展功能的回调中 value 值需以 `key` 开头</li>
        <li>当启用 At、话题等扩展功能时，可使用 options.hint.delay 来减少服务器压力</li>
    </ul>
    <div class="fn-50"></div>
    <div class="actions">
        <button class="btn btn--small"
                onclick="setHint(this, {value: '由于跨域问题，可前往[完整示例](https://ld246.com/guide/markdown)进行体验'})">
            @、话题等关键字扩展
        </button> &nbsp;
        <button class="btn btn--small"
                onclick="setHint(this, {hint:{emoji: {'sad': '💔','j': 'https://cdn.jsdelivr.net/npm/vditor@1.3.1/dist/images/emoji/j.png'}}})">
            自定义表情
        </button> &nbsp;
        <button class="btn btn--small" onclick="setHint(this, {hint:{emojiTail: emojiTail}})">设置表情提示文案
        </button> &nbsp;
        <button class="btn btn--small"
                onclick="setHint(this, {hint:{emojiPath: 'https://cdn.jsdelivr.net/npm/vditor@3.2.0/dist/images/emoji'}})">
            设置表情图片地址
        </button>
    </div>
    <div id="vditor"></div>
    <div id="vditorDemoCode" class="vditor-reset">
        <pre><code class="javascript">new Vditor('vditor', {
  height: 360,
})
</code></pre>
    </div>
    <div class="fn-100"></div>
    <div class="fn-clear">
        <h2 class="fn-left">参与讨论</h2>
        <span class="fn-right" style="line-height: 36px" id="commentCnt"></span>
    </div>
    <div class="fn-50"></div>
    <div id="vditorComments"></div>
    <div class="fn-100"></div>
</div>
<!-- end main -->

<div class="footer">
    <div class="wrapper fn-clear">
        <a href="https://b3log.org">首页</a> &nbsp; &nbsp;
        <a href="https://ld246.com" target="_blank">社区</a> &nbsp; &nbsp;
        <a href="https://b3log.org/brand-marking.html">品牌标识</a> &nbsp; &nbsp;
        <a href="https://ld246.com/sponsor" target="_blank">成为赞助者</a>
        <div class="fn-right">
            <a href="https://beian.miit.gov.cn/" target="_blank">滇ICP备14007358号-1</a> &nbsp; &nbsp;
            © 2023 云南链滴科技有限公司
        </div>
    </div>
</div>
<script>
  let vditorObj
  const emojiTail = '<a href="https://ld246.com/settings/function" target="_blank">设置常用表情</a>'
  const setHint = (it, options) => {
    if (vditorObj) {
      vditorObj.destroy()
    }
    const mergedOptions = Object.assign({
      height: 360,
    }, options)
    if (it) {
      if (options.value) {
        const hintOptions = {
          cache: {
            enable: false,
          },
          height: 360,
          value: '由于跨域问题，可前往[完整示例](https://ld246.com/guide/markdown)进行体验',
          hint: {
            extend: [
              {
                key: '@',
                hint: (key) => {
                  if ('vanessa'.indexOf(key.toLocaleLowerCase()) > -1) {
                    return [
                      {
                        value: '@Vanessa',
                        html: '<img src="https://avatars0.githubusercontent.com/u/970828?s=60&v=4"/> Vanessa',
                      }]
                  }
                  return []
                },
              },
              {
                key: '#',
                hint: (key) => {
                  if ('vditor'.indexOf(key.toLocaleLowerCase()) > -1) {
                    return [
                      {
                        value: '#Vditor',
                        html: '<span style="color: #999;">#Vditor</span> ♏ 一款浏览器端的 Markdown 编辑器，支持所见即所得（富文本）、即时渲染（类似 Typora）和分屏预览模式。',
                      }]
                  }
                  return []
                },
              }],
          },
        }
        updateCode(it, `new Vditor('vditor', {
  cache: {
    enable: false,
  },
  height: 360,
  value: '由于跨域问题，可前往[完整示例](https://ld246.com/guide/markdown)进行体验',
  hint: {
    extend: [
      {
        key: '@',
        hint: (key) => {
          if ('vanessa'.indexOf(key.toLocaleLowerCase()) > -1) {
            return [
              {
                value: '@Vanessa',
                html: '&lt;img src="https://avatars0.githubusercontent.com/u/970828?s=60&v=4"/> Vanessa',
              }]
          }
          return []
        },
      },
      {
        key: '#',
        hint: (key) => {
          if ('vditor'.indexOf(key.toLocaleLowerCase()) > -1) {
            return [
              {
                value: '#Vditor',
                html: '<span style="color: #999;">#Vditor</span> ♏ 一款浏览器端的 Markdown 编辑器，支持所见即所得（富文本）、即时渲染（类似 Typora）和分屏预览模式。',
              }]
          }
          return []
        },
      }],
  },
})`)
        vditorObj = new Vditor('vditor', hintOptions)
        return
      }
      updateCode(it, `new Vditor('vditor', ${JSON.stringify(mergedOptions, null, '  ')})`)
    }
    vditorObj = new Vditor('vditor', mergedOptions)
  }
  vditorScript = setHint
</script>
</body>
</html>
